/*
 * OpenSCAD File with the code to draw a part of the quadcopter in 3D
 * Part Number: 05
 * Version: 0.01
 * Units: mm
 * Last Modification: Sun Jun 27 23:32:08 WEST 2010
 *
 * Copyright (C) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

frominclude = 0;

p5_mcylinder = 12+4+2;
p5_zcdeviation = (p5_mcylinder/2)-1;
p5_sizewidth = 31;

module p5_pipesin()
{
	for (pos = [[12, 12, p5_zcdeviation],[-12, 12, p5_zcdeviation],
				[12, -12, p5_zcdeviation],[-12, -12, p5_zcdeviation]]) {
		translate(v = pos) {
			cylinder(h=p5_mcylinder, r=1.5, center=true, $fn=60);
		}
	}
}

module p5_pipesout()
{
	for (pos = [[12, 12, p5_zcdeviation],[-12, 12, p5_zcdeviation],
				[12, -12, p5_zcdeviation],[-12, -12, p5_zcdeviation]]) {
		translate(v = pos) {
			cylinder(h=12+4+2, r=3.5, center=true, $fn=60);
		}
	}
}

module p5_holesinconnections()
{
	for(z = [45, -45, 90+45, -90-45]) {
		rotate(a=[90, 0, z]) {
			// top
			translate(v = [-10.25, 18-1-2.5-2, 0]) {
				cylinder(h=3, r=2.5, center=true, $fn=60);
			}
			// bottom
			translate(v = [-10.25, 2.5+1+2, 0]) {
				cylinder(h=3, r=2.5, center=true, $fn=60);
			}
		}
	}
}

module p5_holesinabutment()
{
	rotate(a=[90,0,0]) {
		translate(v = [(p5_sizewidth/2)-1-1, 2+1, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
		translate(v = [-(p5_sizewidth/2)+1+1, 2+1, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
	}
}

module p5_pipesconnections()
{
	translate(v = [0, 0, ((12+4+2)/2)-1]) {
		rotate(a=[0, 0, 45]) {
			cube(size = [2, 30, 12+4+2], center=true);
		}
		rotate(a=[0, 0, -45]) {
			cube(size = [2, 30, 12+4+2], center=true);
		}
	}
}

module p5_subcomponent()
{
	rotate(a=[90,0,0]) {
		translate(v = [0, (4/2)-1, 0]) {
			cylinder(h=p5_sizewidth+1, r=2, center=true, $fn=60);
		}
	}
	// hole in central cylinder
	translate(v = [0, 0, ((12+4+2-4)/2)+3]) {
		cylinder(h=12+4+2-4, r=5, center=true, $fn=60);
	}
	p5_pipesin();
	p5_holesinconnections();
	p5_holesinabutment();
	translate(v = [0, 0, -2]) {
		cube(size = [p5_sizewidth+1, p5_sizewidth+1, 2], center=true);
	}
	translate(v = [0, 0, -1]) {
		cube(size = [2, p5_sizewidth+2, 2], center=true);
	}
}

module p5_addcomponent()
{
	cube(size = [p5_sizewidth, p5_sizewidth, 2], center=true);
	rotate(a=[90,0,0]) {
		translate(v = [0, (8/2)-3, 0]) {
			cylinder(h=p5_sizewidth, r=4, center=true, $fn=60);
		}
	}
	// central cylinder
	translate(v = [0, 0, ((12+4+2)/2)-1]) {
		cylinder(h=12+4+2, r=7, center=true, $fn=60);
	}
	p5_pipesout();
	p5_pipesconnections();
	// abutment
	translate(v = [0, 0, (6/2)-1]) {
		cube(size = [p5_sizewidth, 2, 6], center=true);
	}
}

module part05()
{
	difference() {
		union() {
			p5_addcomponent();
		}
		p5_subcomponent();
	}
}

if(frominclude == 0) {
	part05();
}
